package FlashServer;

import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class GameServer extends Thread 
{
	private ServerSocket FServerSocket;
	ThreadPool FPool;

	public GameServer(int port, int poolSize) throws IOException 
	{
		FPool = new ThreadPool(poolSize);
		FServerSocket = new ServerSocket(port);
		System.out.println("Server launched: ");
		System.out.println("IP: " + InetAddress.getLocalHost().getHostAddress());
		System.out.println("Port: " + FServerSocket.getLocalPort());
	}

	@Override
	public void run() {
		while (true) 
		{
			try 
			{				
				Socket socket = FServerSocket.accept();
				SocketHandler vWorker = FPool.getWorkerThread();
				if (vWorker != null)
					vWorker.ProcessSocket(socket);
				else
					socket.close();

			} 
			catch (Exception ex) 
			{}
		}
	}
}
